package com.hbu.search.hbumallsearch.controller;

import com.hbu.common.TO.es.SkuEsModel;
import com.hbu.common.exception.BizCodeEnum;
import com.hbu.common.utils.R;
import com.hbu.search.hbumallsearch.service.ElasticSearchService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

/**
 * @ProjectName: hbu-mall
 * @Package: com.hbu.search.hbumallsearch.controller
 * @ClassName: ElasticSearchSaveController
 * @Author: zxh
 * @Description:
 * @Date: 2022/12/5 12:15
 * @Version: 1.0
 */
@RestController
@AllArgsConstructor
@RequestMapping("/search/save")
public class ElasticSearchSaveController {

    private ElasticSearchService elasticSearchService;

    @RequestMapping(value = "/product",method = RequestMethod.POST)
    public R productShelves(@RequestBody List<SkuEsModel> skuEsModelList) {

        try {
            elasticSearchService.productShelves(skuEsModelList);
        } catch (IOException e) {
            return R.error(BizCodeEnum.PRODUCT_UP_EXCEPTION.getCode(),BizCodeEnum.PRODUCT_UP_EXCEPTION.getMsg());
        }
        return R.ok();
    }
}
